import dayjs from 'dayjs';
import { CalendarPicker } from 'antd-mobile';
import { useState } from 'react';
interface Props {
  handleDateChange: (data: any) => void;
  handleQuickSelect: (range: number, activeRange: string) => void;
  dateRange: [dayjs.Dayjs, dayjs.Dayjs];
  activeRange: string;
}

const MobileReportHeader = ({
  handleDateChange,
  handleQuickSelect,
  dateRange,
  activeRange,
}: Props) => {
  const [visible, setVisible] = useState(false);
  return (
    <div>
      <div className="mb-2 w-full rounded-default bg-white p-3">
        <div className="flex items-center justify-between">
          <div className="flex gap-2">
            <div
              className={`rounded px-3 py-1 text-sm ${
                activeRange === '7days' ? 'bg-[#E8F3FF] text-[#1E6FFA]' : 'bg-fill-1 text-text-3'
              }`}
              onClick={() => handleQuickSelect(7, '7days')}
            >
              近7天
            </div>
            <div
              className={`rounded px-3 py-1 text-sm ${
                activeRange === '30days' ? 'bg-[#E8F3FF] text-[#1E6FFA]' : 'bg-fill-1 text-text-3'
              }`}
              onClick={() => handleQuickSelect(30, '30days')}
            >
              近30天
            </div>
          </div>

          <div
            className="flex cursor-pointer items-center gap-2 rounded border border-line-2 px-2 py-1 text-sm text-text-3"
            onClick={() => setVisible(true)}
          >
            <span>{dateRange[0].format('YYYY-MM-DD')}</span>
            <span>~</span>
            <span>{dateRange[1].format('YYYY-MM-DD')}</span>
          </div>
        </div>

        <CalendarPicker
          visible={visible}
          selectionMode="range"
          onClose={() => setVisible(false)}
          defaultValue={[dateRange[0].toDate(), dateRange[1].toDate()]}
          onConfirm={(val) => {
            if (Array.isArray(val) && val[0] && val[1]) {
              handleDateChange([dayjs(val[0]), dayjs(val[1])]);
            }
            setVisible(false);
          }}
        />
      </div>
    </div>
  );
};

export default MobileReportHeader;
